load("//bazel:tachyon_cc.bzl", "tachyon_cc_library", "tachyon_cc_unittest")

package(default_visibility = ["//visibility:public"])

tachyon_cc_library(
    name = "cycle_store",
    srcs = ["cycle_store.cc"],
    hdrs = ["cycle_store.h"],
    deps = [
        ":label",
        "//tachyon/base/containers:container_util",
    ],
)

tachyon_cc_library(
    name = "grand_product_argument",
    hdrs = ["grand_product_argument.h"],
    deps = [
        "//tachyon/base:parallelize",
        "//tachyon/zk/base/entities:prover_base",
    ],
)

tachyon_cc_library(
    name = "label",
    hdrs = ["label.h"],
    deps = [
        "//tachyon:export",
        "//tachyon/zk/base:row_types",
    ],
)

tachyon_cc_library(
    name = "permutation_argument",
    hdrs = ["permutation_argument.h"],
    deps = [
        "//tachyon:export",
        "//tachyon/base/containers:contains",
        "//tachyon/zk/plonk/base:column_key",
    ],
)

tachyon_cc_library(
    name = "permutation_assembly",
    hdrs = ["permutation_assembly.h"],
    deps = [
        ":cycle_store",
        ":label",
        ":permutation_argument",
        ":permutation_proving_key",
        ":permutation_verifying_key",
        ":unpermuted_table",
        "//tachyon:export",
        "//tachyon/base:openmp_util",
        "//tachyon/base/containers:container_util",
        "//tachyon/zk/base/entities:prover_base",
        "//tachyon/zk/plonk/halo2:vendor",
        "//tachyon/zk/plonk/vanishing:vanishing_utils",
    ],
)

tachyon_cc_library(
    name = "permutation_evaluator",
    hdrs = ["permutation_evaluator.h"],
    deps = [
        ":permutation_prover",
        "//tachyon/base:profiler",
        "//tachyon/zk/plonk/vanishing:circuit_polynomial_builder_forward",
        "//tachyon/zk/plonk/vanishing:vanishing_utils",
    ],
)

tachyon_cc_library(
    name = "permutation_opening_point_set",
    hdrs = ["permutation_opening_point_set.h"],
)

tachyon_cc_library(
    name = "permutation_prover",
    hdrs = [
        "permutation_prover.h",
        "permutation_prover_impl.h",
    ],
    deps = [
        ":grand_product_argument",
        ":permutation_argument",
        ":permutation_opening_point_set",
        ":permutation_proving_key",
        ":permutation_table_store",
        ":permutation_utils",
        "//tachyon/base:profiler",
        "//tachyon/base:ref",
        "//tachyon/base/functional:functor_traits",
        "//tachyon/crypto/commitments:polynomial_openings",
        "//tachyon/zk/base:blinded_polynomial",
        "//tachyon/zk/base:row_types",
        "//tachyon/zk/base/entities:prover_base",
        "//tachyon/zk/plonk/base:multi_phase_ref_table",
    ],
)

tachyon_cc_library(
    name = "permutation_proving_key",
    hdrs = ["permutation_proving_key.h"],
    deps = ["//tachyon/zk/plonk/keys:c_proving_key_impl_forward"],
)

tachyon_cc_library(
    name = "permutation_table_store",
    hdrs = ["permutation_table_store.h"],
    deps = [
        ":permuted_table",
        ":unpermuted_table",
        "//tachyon/zk/plonk/base:ref_table",
        "@com_google_absl//absl/types:span",
        "@com_google_googletest//:gtest_prod",
    ],
)

tachyon_cc_library(
    name = "permutation_utils",
    hdrs = ["permutation_utils.h"],
    deps = [
        # TODO(chokobole): Remove this dependency once fixing issue specified in permutation_utils.h.
        "//tachyon/math/elliptic_curves/bn/bn254:fr",
        "//tachyon/base/numerics:checked_math",
    ],
)

tachyon_cc_library(
    name = "permutation_verifier",
    hdrs = ["permutation_verifier.h"],
    deps = [
        ":permutation_opening_point_set",
        ":permutation_utils",
        ":permutation_verifier_data",
        "//tachyon/base/containers:adapters",
        "//tachyon/crypto/commitments:polynomial_openings",
        "//tachyon/zk/plonk/base:l_values",
        "//tachyon/zk/plonk/constraint_system",
    ],
)

tachyon_cc_library(
    name = "permutation_verifier_data",
    hdrs = ["permutation_verifier_data.h"],
    deps = ["//tachyon/zk/plonk/base:multi_phase_evaluations"],
)

tachyon_cc_library(
    name = "permutation_verifying_key",
    hdrs = ["permutation_verifying_key.h"],
)

tachyon_cc_library(
    name = "permuted_table",
    hdrs = ["permuted_table.h"],
    deps = [
        ":label",
        "//tachyon/base:range",
        "//tachyon/base:ref",
    ],
)

tachyon_cc_library(
    name = "unpermuted_table",
    hdrs = ["unpermuted_table.h"],
    deps = [
        ":label",
        ":permutation_utils",
        "//tachyon/base:openmp_util",
        "//tachyon/base:range",
        "//tachyon/base:ref",
        "//tachyon/base/containers:container_util",
    ],
)

tachyon_cc_unittest(
    name = "permutation_unittests",
    srcs = [
        "cycle_store_unittest.cc",
        "permutation_assembly_unittest.cc",
        "permutation_table_store_unittest.cc",
        "permutation_utils_unittest.cc",
        "unpermuted_table_unittest.cc",
    ],
    deps = [
        ":permutation_assembly",
        ":permutation_table_store",
        "//tachyon/math/elliptic_curves/bn/bn254:fq",
        "//tachyon/math/elliptic_curves/short_weierstrass/test:sw_curve_config",
        "//tachyon/math/finite_fields/test:finite_field_test",
        "//tachyon/math/finite_fields/test:gf7",
        "//tachyon/math/polynomials/univariate:univariate_evaluation_domain_factory",
        "//tachyon/zk/plonk/halo2:bn254_shplonk_prover_test",
    ],
)
